<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Home\Model;

/**
 * Description of GoodsModel
 *
 * @author Administrator
 */
class GoodsModel extends \Think\Model{
    
    /**
     * 
     * @param type $goods_status  商品状态
     * @param type $limit  取出多少条
     */
    public function getGoodsListByGoodsStatus($goods_status,$limit=5){
        $cond = [
          'goods_status &'.$goods_status,
           'status'=>1,
            'is_on_sale',
        ];
        return $this->field('id,name,logo,shop_price')->where($cond)->select();
    }
    
    public function getGoodsInfo($id){
        //1.获取基本信息
        $cond = [
          'status'=>1,
            'is_on_sale'=>1,
            'id'=>$id,
        ];
        $row = $this->where($cond)->find();
        if(!$row){
            $this->error = '商品飞走了';
        }
        //2.获取详细描述
        $row['brand_name'] = M('Brand')->where(['id'=>$row['brand_id']])->getField('name');
        
        $row['content'] = M('GoodsIntro')->where(['goods_id'=>$id])->getField('content');
        //获取相册列表
        $row['galleries'] = M('GoodsGallery')->where(['goods_id'=>$id])->getField('path',true);
        //返回
        return $row;
    }
}
